package model;

import java.util.ArrayList;
import java.util.HashMap;

public class VarValueList {

	//private String termId;
	Value idValue;
	private HashMap<String, Value> internalMap = new HashMap<String, Value>();

	public VarValueList(String term, ArrayList valueList) {
		ArrayList<String> varList = StringAnalyser.getVarsList(StringAnalyser
				.getElementsInTermList(term));
		// connect Var- and value-list:
		int varIndex=0;
		int valueIndex=0;
		while (varIndex<varList.size()) {
			String id = varList.get(varIndex);
			varIndex++;
			Value v;
			if (StringAnalyser.isANumber(id)) {
				v = new Value(id);
			}
			else {
				v = new Value(valueList.get(valueIndex));
				valueIndex++;
			}
			internalMap.put(id, v);
		}
	}

	@Override
	public String toString() {
		return internalMap.toString();
	}

	public Value getValue(String varName) {
		return internalMap.get(varName);
	}

	public void setValue(String id, Value value) {
		internalMap.put(id, value);
		idValue=value;
		//internalMap.put(termId, execute);
	}

	// public void updateValue(Value x) {
	// internalMap.put(x.id, x);
	// }

	public Value getResult() {
		return internalMap.get(VarNameFactory.getCurrentId());
	}

}
